/*
 * RecvMediaPort.h
 *
 *  Created on: 2017年4月14日
 *      Author: chuanjiang.zh
 */

#ifndef RECVMEDIAPORT_H_
#define RECVMEDIAPORT_H_

#include "MediaPort.h"
#include "Process.h"
#include "Sdp.h"
#include "RtpMedium.h"
#include "JRTPSession.h"
#include "RtpRecvState.h"
#include "OrderCache.h"
#include "SharedPtr.h"
#include "TCriticalSection.h"
#include "Flowmeter.h"
#include "CRtpSink.h"


class RecvMediaPort : public MediaPort
{
public:
	RecvMediaPort();
	virtual ~RecvMediaPort();

	virtual void setOriginSdp(const std::string& sdp);

	virtual std::string getLocalSdp();

	virtual int setPeerSdp(std::string& peerSdp);

	virtual std::string getPeerSdp(std::string& offerSdp);

	virtual int start();

	virtual void stop();

	void setPath(const std::string& player, const std::string& dumpfile);

	void handlePacket(StreamPacket* pPacket);

protected:
	

protected:
	std::string apply(const std::string& localSdp, const std::string& peerSdp);

	int setup(const std::string& localSdp, const std::string& peerSdp);

	bool setupMedium(sdp::SessionDescription& local, sdp::SessionDescription& peer,
		const char* name, RtpMedium& rtpMedium, int& localPort);

	std::string getName();

protected:
	CRtpSink	m_rtpSink;

	std::string m_originSdp;

	std::string m_localSdp;
	std::string m_peerSdp;
	bool    m_connected;

	Process m_player;
	std::string m_playerPath;

	std::string m_dumpPath;

	RtpMedium m_medium;

	bool m_running;

	int	m_localPort;

	comn::CriticalSection	m_cs;
	
	int	m_pktCount;

};

#endif /* RECVMEDIAPORT_H_ */
